Skip to main content

Full text of "Control PID Fuzzy Logic Shifting Gears OCR"

MOTOROLA 



KBG . EXE 

A Fuzzy Logic 
Knowledge Base Generato 

for the 
MC68HC11 and MC68HC05 
Inference Engines 



M) MOTOROLA 



Program KBG.EXE creates and edits a knowledge base, runs a software 
simulation of an inference engine, and uses the simulation engine to create a 2-D 
plot of the control surface described by your knowledge base. This tutorial 
demonstrates the use of program KBG.EXE to create a new knowledge base file for 
a FUZZY logic application. KBG.EXE acts as a preprocessor to generate a 
knowledge base for either the MC68HC11 or MC68HC05 inference engine, 
FUZZY11B.ASM or FUZZY05B.ASM, using natural language inputs. At present, 
only FUZZY11B.ASM is available; FUZZY05B .ASM will be available soon.) The 
inference engines require the FUZZY knowledge base to be in the form of 
assembly language constants (FCB - Form Constant Byte directives) scaled from 
to 255. This is a data structure that the MC68HC11 or MC68HC05 assemblers can 
understand. KBG.EXE performs the following operations: 

1. Creates a knowledge base in a natural language format. 

2. Loads an existing knowledge base. 

3. Saves the current knowledge base. 

4. Edits a knowledge base. 

5. Generates a print file. 

6. Generates the MC68HC11 or MC68HC05 assembly code file. 

7. Runs a software emulation of the inference engine. 

8. Displays a 2-D slice of the control surface. 

The current version of KBG.EXE is compiled to accept; 

1. 8 Inputs. 

2. 4 Outputs. 

3. 8 Membership functions per input. 

4. 8 Membership functions per output. 

5. 1024 rules. 

6. Any number of inferences per rule. 

7. 15 characters per name (input, output, member). 

8. 4 points per input member. 

9. 1 point per output member. 

Future versions of this program will be posted on Motorola's Freeware BBS as 
they become available. You can reach the Freeware BBS at (512) 891-FREE. 
Connect at 2400, 1200, or 300 baud with 8 bits, No Parity, and 1 Stop Bit. The 
Freeware BBS System also has the code for the MC68HC11 and MC68HC05 
Inference Engines. 

This tutorial uses the IBM-PC version of KBG.EXE to demonstrate creation of a 
new knowledge base. KBG.EXE requires a VGA graphics adapter. If available, 
use a '386 or '486 based machine; some functions may be unacceptably slow on a 
PC equipped with an older microprocessor. 



2 



M) MOTOROLA 



The FUZZY Logic example presented here shows the coding of the classic inverted 
pendulum balancing problem. This problem consists of variable amount of mass 
atop a variable length rod. The base of the rod is moved to balance the rod and 
mass. This example shows how to code the problem as presented in chapter 8 of 
Bart Kosko's book, Neural Networks and Fuzzy Systems (Prentice Hall). 

The figure to the left shows a schematic of 
the problem situation. For this example, 
consider only motion on the X-Y axis, not 
the Z axis. This simplifies the problem to 
only two inputs. Input 1 is the angle (phi) 
of the pendulum to the vertical. Input 2 is 
the rate of change of the angle (delta phi) 
in degrees per second. 

Once you identify the inputs, you must 
create membership functions for each 
input. Input 1 requires seven membership 
functions. A negative deflection of the 
angle is within one of three members. A 
large deflection, -36 to -90 degrees, is 
labeled Negative_Large (NL). A lesser defection, between -18 and -54 degrees, is 
labeled Negative_Medium (NM). A deflection of to -36 degrees is labeled 
Negative_SmaIl (NS). The three positive deflections are symmetrical, and are 
similarly cfefined. A deflection of Zero (ZE) occurs from -18 to +18 degrees. As is 
the case with fuzzy logic, a particular deflection can fall into more than one 
membership function. For example, a deflection of -5 degrees is Zero to a great 
extent and Negative_Small to a lesser extent. 

Input 2 is almost identical, but refers to rate of change. Thus, a value of +30 
means +30 degrees / second change. See the following diagram for the details of 
input membership functions. 




3 



MOTOROLA 



NL NA NS ZE PS PA PL 





- — \ f\ 
1 > 

\/ \ / 
/\ \ / 


AAA 








1 •!• 1 •» -VI 





-90 60 -30 .30 '60 '90 



ANGLE 



NL NA NS ZE PS PA PL 




-90 60 -30 «30 *60 »90 



DELTA ANGLE 



This system has only one output. The output controls the motor rotation to move 
the balance point right or left. The membership functions for the output are 
shown in the following figure. Three levels of drive current for the motor in each 
direction are defined, and zero current is defined for the stopped condition. The 
seven motor current levels are: 



NL NegativeJLarge 

NM Negative _Medium 

NS Negative _£mall 

ZE Zero 

PS Positive _gmall 

PM Positive JMedium 

PL Positive JLarge 



4 



MOTOROLA 



Output M 



NL 
Q 



NA 

© 



NS 
Q 



ZE 
Q 



PS 
Q 



PA 
Q 



PL 
© 



18 -12 -6 6 12 18 

AOTOR CURRENT 



The MC68HC11 and MC68HC05 Inference Engines define outputs as singletons; 
thus, only one discrete point defines each output. 

Now to begin the coding exercise; the first step is to execute KBG.EXE. 

C:>kbg 



As KBG begins, you see a signon screen with the Motorola copyright notice. PreBS 
any key to proceed to the Main Menu. 



Knovlacfaa Basa Danarator <K8Q) UX . lO 
<Copvrlo*tt Motorola Inc. 1**1,1993) 



KBO Ha In Ptanu . 
L - Load Knovladaa Bau Flit. 
X - Saw krtouladaa llaaa Fi la. 
C - Edit Knowladoa Bas« Fll*. 
P - Craata PRINT Output Ft la. 
A - Kafca AaaaMblw Coda Fl la. 
D - Draw Cntr* 1 turfaea Plot. 
K - Show Enalna Execution. 
Q - Datum to DOS fron KBQ. 



KBG.EXE has an on-line help system that you can activate by pressing the H key. 
The help system displays help menus and/or text in a window. You can use the 
up and down arrow keys to select a topic for help. The ENTER key activates the 
help text or submenus for the selected topic. Use the ESCAPE key to exit the help 
system and the BACKSPACE key to back up to the previous display, either text or 
menu. 



5 



MOTOROLA 



At this point, KBG.EXE contains no data to describe a knowledge base. With 
KBG.EXE, you can load a previously created knowledge base or create a new one. 
This tutorial demonstrates creating a new one. Begin by selecting E from the 
Main Menu. This clears the screen and calls up the Edit Menu, displayed by the 
subsystem you use to describe a new base or to modify an existing base. 

KnouladOM Bim QarMtrator <KBQ> US.IO 
CCoourloht Motorola Inc. 1991.199ft> 



KBG Edit Menu. 
I - Inputs: Add, Edit, D«I«t«. itanbars. 
O - Outputs: Odd, Edit. Dvlala, mnbars. 
R - Rules: Odd, Oa lata Ruins. 

Q - Quit to MAIM rtanu. 



You may add either the inputs or the output now, in any order. However, it would 
make no sense to define rules now, with no inputs, outputs, or membership 
functions to reference. 

In this case, add the inputs first. Selecting I for inputs brings up the data entry 
screen for inputs, as shown in the following figure. The eight inputs are displayed 
in a window at the upper left corner of the monitor screen. Each undefined input 
shows a single tilde (~) as the input name. In this case, all inputs are undefined 
and all inputs show tildes as their names. 



6 



(M) MOTOROLA 



KnouladM B*M Omntor < KBQ) U2.10 
(Copurlght Motorola Inc. 1991.1998) 



1-" 
»-" 

3- ' 

4- " 
3-" 

6- " 

7- " 
8 -" 



I INPUT » 1 



E- Edit Input. 
n- Snow Hent>«ra 
Q- Quit. 

I COMANDS ] 



t«l«ct an INPUT (1=>9) or Quit. 



I DIftLOO 1 



Next, press a number key, 1 through 8. This selects an input for editing. The 
inputs can be defined in any order. The selected input is underlined in the left 
window. Another window is opened in the upper center of the monitor screen, as 
shown in the following figure. This window shows the current Name, Units, 
Minimum, and Maximum for the selected input. Press the 1 key and note that the 
Name and Units for input #1 are undefined. Both the Minimum and Maximum 
are zero (undefined). 



7 



M) MOTOROLA 



KnowlKKNi Bm« Dmrttor tKBQ) UZ.IO 
CCopurlflftt Motorola Inc. 1991, 19?3> 






name: 




E- Edit Input. 




units: 




fl- Show ItoMtHtr*. 




minimum: 




Q- Quit. 


o 










MAXIMUM: 






o 














( COMMANDS ] 



S«lKt Edit, H*r*>«>r, or Quit. 



t DIALOG 1 

Next, press the E key to edit input #1. The NAME field in the center window is 
underlined to show that it is selected. Pressing the ENTER key selects the NAME 
field for edit and opens an edit window below the other two. At the prompt (>) in 
the edit window, type the name of input #1 - Angle. Press the ENTER key; the edit 
window should vanish and the program should display the word Angle in the 
NAME field in the center window. This shows that the name you typed has been 
placed in the knowledge base. The underline is moved to the UNITS field to show 
that it is now selected instead of the NAME field. Press the ENTER key and enter 
the word Degrees as the name for UNITS. In the same way, enter -90 for 
MINIMUM and 90 for MAXIMUM. 

After you enter the last item for input #1, the program removes the center window 
and writes the name Angle in the left window as the name for input #1. The other 
data for this input is stored in the knowledge base but is not displayed on this 
screen. 



8 



MOTOROLA 



Knowladv* Bm%m Oenarator <KBO> U3 . 10 
< Copyright no t o ro J • Ir»c, 1991, 1»»I> 



NAME * 
Orvtlm 

UHITXl 



C- Edit Input. 



H- SIkmj ttanbars. 




Q- Quit. 



-90 

maximum: 

90 



[ INPUT! 1 



C COWHANDS 1 



Salact Edit, Htnlwr, or Quit. 



C DIALOG 1 1 

Now, select input #2 for edit and enter Delta Angle for NAME, Degrees Second 
for UNITS, -90 for MINIMUM, and 90 for MAXIMUM. Both inputs "are now 
defined, but contain no membership functions. 

To enter membership functions, select Input #1, Angle, and press the M key for 
Members. The program clears the screen and displays three windows, as shown 
in the following figure. The top window shows membership functions on a graph; 
the X-axis represents values from MINIMUM to MAXIMUM and the Y-axis 
represents degree of membership. Each point on the X-axis is represented by a 
two number pair, such as -90,0 or 0,128. The first number of the pair represents 
the natural language input value and the second number is the internal 
representation. The second is a number from to 255 (one byte). In this example, 
the value -90 is the same as MINIMUM and is represented as zero. Likewise, the 
input value +90 is the same as MAXIMUM and is represented as 255. All input 
values between -90 and +90 are scaled to a number through 255. (You do not have 
to know the internal representation, but knowing may help you to understand the 
final assembly language output). 

The numbers on the Y-axis are represented by the same type of two-number pairs. 
The first number, through 1 (0% through 100%), is the degree of membership 
and the second number is the internal representation. 

The center window shows the names and values of membership functions in a 
tabular format using two tables. The ORIGINAL table shows members in input 



9 



(M) MOTOROLA 

format. The table labeled PT. SLOPE shows the same data represented as point- 
slope pairs. 

The bottom window displays available commands. It changes as data entry modes 
change. The initial key commands are s, r, q, a, and <CR>, listed below: 

s exchanges the position of the two tables in the center window. No data is 

modified. 

r redraws the entire screen; no data is modified, 

q quits, and returns to the preceding menu, 

a adds a new membership function. 

<CR> activates the edit mode. 



1,233 



-90.0 


-An. 6* 








49,191 


90,833 



o. oi 



OHIOI MflL 



1 : 
a: 
a: 
4: 
s: 
c: 
?: 
• t 



o 
o 
o 
o 
o 
o 
o 
o 



o 
o 
o 
o 
o 
o 
o 
o 



o 
o 
o 
o 
o 
o 
o 
o 



o 
o 
o 
o 
o 
o 
o 
o 



PT . SLOPE 1 : 






O 


6 


O 


6 


a: 




m 








O 





at 






O 


O 


O 


o 


4: 






O 


O 


O 


o 


9: 






O 


O 


O 


o 


«: 






O 


O 


o 


o 


7: 






O 


o 


o 


o 


• : 






O 


o 


o 


o 




r- rmdrmu. 








ult. 




*-<K*d fune. 


<cn>-adlt 













10 



® 



MOTOROLA 



Continuing this example, press the a key to begin entry of the first membership 
function. Text in the bottom window now requests the name of the membership 
function. Type Negative_Large as the name for the first membership function. 
Names can be as long as 15 characters, with upper case, lower case, and/or 
underscore characters. The program displays the name in the two tables and 
requests point #1. Enter -90. The program writes the value -90 into the tables, 
draws a line on the graph at -90 on the X-axis, and requests point #2. Enter -90. 
The same scenario repeats. Enter -54 for point #3 and -36 for point #4. 



1. 233 



-45.64 



l: 

a: 
3: 
4: 
3: 
«: 
7: 
fl: 



O 

o 
o 
o 
o 
o 
o 



49.191 



-I 



9o, ass 



-90 

o 
o 
o 
o 
o 
o 
o 



-34 

o 
o 
o 
o 
o 
o 
o 



-36 

o 
o 
o 
o 
o 
o 
o 



O 
o 
o 
o 
o 
o 
o 



PT . SLOPE 



UP. DOMH-Mltct 
func. 



rune. 



1: Kagat iv«J.»r|ia O 

a: 

3: O 

4: o 

3: O 

6: O 

7! O 

a: o 

RIGHT, LEFT-Mlact pt . 
i — rtdrw. 

rt~ rtfimii function. 



O 
O 
O 
O 
O 
O 
O 
O 



SI 
O 
O 
O 
O 

o 
o 
o 



t-ptcfc func. 
a- Quit . 

<cn>-«dtt noda, 



The first membership function has been entered. Note that this is a special case 
trapezoid in which the first two points are at the same point on the X-axis. All 
input membership functions are trapezoids (four points), but may have points at 
the same location. The command menu has changed, but just ignore that for a 
moment and enter the second membership function. The second member is called 
Negative_Medium and has points -54, -36, -36, -18. Press the a key and enter the 
member. Note that this also produces a special case of a trapezoid - a triangle. The 
next four membership functions all have the same shape; generate them by 
copying member #2. 

Member #2 is currently highlighted in the following figure. If it were not, you 
would press the up-arrow or down-arrow keys until it became highlighted. Press 



li 



MOTOROLA 



the t key to select the highlighted member, then press the ENTER key. The 
command menu now offers the c (copy) command. Press the c key and supply the 
name Negative_Small. A new member is drawn on top of the current member. 
We press the right-arrow key and this moves the new member to the right on the 
X-axis. We press the right-arrow key until the leftmost vertex is at -36 on the X- 
axis. You can read this value from the first entry of the ORIGINAL table. Press 
ENTER and the copy operation is complete. 



1,233 



0,0 




-90,0 



-43,64 



ORIQI HM. 



l: 

a: 

3: 
4: 
9: 
C: 

7: 
0: 



43,191 



90,839 



-90 
-34 


o 
o 
o 
o 
o 



-90 
-36 
O 
O 
O 
O 
O 
O 



-34 
-96 
O 
O 

o 
o 
o 
o 



-36 
-17 
O 
O 
O 
O 
O 
O 



-snr 

77 
O 
O 
O 
O 
O 
O 



10 

o 
o 
o 
o 
a 
o 



l : 
a: 

3 : 
4: 
3: 
6: 

7! 

8: 



Mug at i i/«_fWd i un 



O 
51 
O 
O 
O 
O 
O 
O 



O 
10 
O 
O 
O 
O 
O 
O 



up.DOtW-Mlact func. 
m— add func. 



ntQHT,LEFT-Ml*ct pt. 
r- redrag . 

r>- rwimi function. 



t-nlcM func. 
<»-qul». 

<Cn>-«<llt noda. 



Repeat the copy operation for Zero (-18), Positive_Small (0), Positive^Medixun (18), 
and Positive_Large (36). Now seven members are defined, as shown in the 
following figure, but the seventh member, PositiveJLarge has the wrong shape. 
You must edit it. Use the edit function to select any vertex of the member and 
move the vertex to another point on the X-axis. 



12 



M) MOTOROLA 



1. 333 



0.0 
-90, O 




-43, t 4 



43.192 



90. 35S 



1: N«M»«t lu»_l»ra« -90 -*0 -34 -3* 

«: lte«atlvaJ1«dlun -94 -3* -9C -17 

3: HwMtiuaJliMll -3« -17 -17 -1 

4: Zero -It O O 19 

9: Posltlv«_Xnall O 18 18 3* 

C! Poaitlv«_M«diurt 18 St 3C 33 

7: Po» 1 1 lv« J.artw 36 34 34 72 

• > O O O O 



PT. SLOPE 



r-rtdrw. 
•-•ctla tonl< 
q-pu i t . 



N««Hit iva_He«liun SI 10 

N*aatlv«_Snall 77 lO 

Z«ro lot lO 

Po*ltl<M_**all 127 lO 

Poait lv*_tfodlur» 13* 10 

Poiltlu«_Larga ITS 1 □ 

~ O O 

U-UTKlO. 

*»-€*• l«t« func. 
<CR>-Ml«ct 



31 
77 
103 
128 
132 
179 
204 
O 



-10 
10 
-11 
-lO 
-lO 
-lO 
-ID 
O 



RIGHT, LEFT-*ov« pt.func. 
c-cooy func. 



Use the up-arrow or down-arrow key until member #7 is highlighted and then 
press the t key to select the member. Press ENTER to enter the edit mode. Now the 
left-arrow and right-arrow keys can select one of the four vertices of the member. 
Select the right-most vertex, point #4, and press the ENTER key. Next, use the 
right-arrow key to move the vertex to the right until it reaches 90, as shown in the 
following figure. 



13 



MOTOROLA 



1. 233 



o.o 
-»o.o 

onion**" 




-43,64 



l: 
X; 
3: 
4: 
9: 
6: 
7: 
• i 



Naga 
Nagat 
Nh« 

Post 
Posit 
Post 



43,198 



90,335 



t liMi_JLaro>a 
tlv«_Snall 

t lv4t_JL«rv«j 



-90 

-34 
-36 
-18 
O 
18 
36 
O 



-90 
-3* 

-17 
O 
IB 
34 
34 
O 



-34 
-3* 
-17 

18 

at 

34 

o 



-36 
-IT 
-1 
19 
36 
33 
90 
O 



Zmro 
tluaOSnall 

I 1 \fm _JL«r»« 



PT. SLOPE 



1! 

a: 
3: 
4: 
3: 
6: 
7: 
«: 



M*0« 
H«««t 
Haga 

Post 
Posit 
Post 



O 
51 
77 

10a 

137 
133 
178 
O 



O 
lO 
lO 
lO 
lO 
lO 
lO 

O 



31 
77 
103 
138 
133 
179 
304 
O 



-lO 
-10 
-11 
-lO 
-10 
-lO 
-3 




r-rsrdrsu. 
•-•Call to99li 



u-undo. 

Q-QUlt • 



RIGHT, LEFT 
<cn>-salact 



novm pt, rune. 



Notice that the seventh member is no longer an isosceles triangle, but is now 
asymmetrical. The member needs more editing. Notice also that the values in the 
right columns of the ORIGINAL and PT. SLOPE tables have changed, consistent 
with the new location of vertex #4. Next, select vertex #3 and move it to 90. The 
following figure shows the screen with vertex #3 at 67, an intermediate point. 



14 



M) MOTOROLA 



1. 193 



0,04 

-90. O 




-45,64 



OFUQINM- 



1: 

21 

3: 
4i 
3: 
«: 
7: 
a: 



Hm&at lu*_lLar0a -90 



49,193 



90,339 



N*««t lva_Kadlun 
Zara 

Posltiva_SK«lI 
Po» 1 t lv*_ftadlun 
Po» 1 1 1 v«_L*r»a 



-34 
-34 
-1« 
O 
19 
36 
O 



-90 
-36 
-17 
O 
1« 
3ft 
34 
O 



-34 
-36 
-17 
O 
13 
36 
67 
O 



-3< 

-tl 

11 
3« 

35 
90 
O 



Tl N«fl«t ii>«_L»r»a 5 O 

2: Ne«atiua_H«dii»« 51 10 77 

3: H*9«t loa^Snjil 1 77 10 103 

4: Zaro 102 10 133 

3: PosltiuOnal I 137 10 133 

6: Posidvajhidiun 193 10 179 

7: Pm 1 1 tv«_L*r9* 179 lO 223 

a: O O O 



Pt . SLOPE 



-lO 
-10 

-11 

-lO 
-10 
-lO 

-• 
o 



i — redraw. 



-quit. 



RIGHT, LEFT-nov« pt.rune. 
<cn>-s«Iact ncn*m. 



Normally, you would not stop at this intermediate point. This figure is shown to 
help you to understand the transition of the member from a triangle to a 
trapezoid. Again, notice the effect of moving the vertex on the values in the tables. 
When you continue to move the vertex to 90, the screen changes as shown in 
following figure. The membership entry is complete. 



15 



M) MOTOROLA 



1, 333 



0, 04 

-90, O 



l: 
a: 
3: 
4: 
9: 
«i 
7: 
• : 




90, zss 



Zmro 

Posit 1 «j«_S mil 
Po» 1 1 iv*_fte<l tun 
Po* 1 1 iv« __L»* »• 



-90 
-54 
-38 
-18 

19 
36 




-90 
-3< 
-17 
O 
18 
34 
94 
O 



-94 
-»« 
-IT 
O 
18 
34 
90 
O 



-34 
-IT 
-1 
19 
34 
59 
90 
O 



PT. SLOPE 



i — redr»vi. 



1: H«g»t tu«_Larg« O 

2! N«g»t iv«_J1fKJiun 51 

3: N»a«t lu«_lnal I 77 

4: Zero 103. 

9: PosltluaJlMll 117 

«: Posit lw«_P«Kllim 198 

7: Po* 1 1 i\sm_J ar&m 178 

8 : - O 

u-undo. 
q-qult. 



O 
lO 

io 

lO 
IO 
IO 
IO 

o 



51 
77 
108 
128 
198 
179 
893 
O 



-IO 
-10 
-11 
-IO 
-IO 
-IO 

o 
o 



RIGHT , LEFT-nov* pt.func. 
<Cfl>-*«lect nod*. 



Enter the remaining input and output data in the same manner; then proceed to 
the heart of the matter, the rules. The rules and their treatment by the inference 
engine are the prime function of Fuzzy Logic. Rules are written by selecting 
inputs, outputs, and membership functions from a window. Use the q key to 
return to the Edit Menu. From this menu, the r key shows the following screen. 



16 



M) MOTOROLA 



Knowledge Bau Owttritor <KBG) VZ . 10 
(Cooyrtgfrit Motorola Inc. 1991,1992) 

A - Add Navi RuI*. 
D - O* lata m FUj 1 m . 

Q - Quit. 

t COMMAND 1 



t CURRENT RULES J 



Select the a key to begin entry of the first rule. Build the rule in the right hand 
window, clause by clause. First, place the word IF in the new rule window. The 
next item in a rule is an input clause, which consists of an input and a 
membership function for that input. The program displays inputs in the left hand 
window and a prompt in the Dialog window to request an input number, as 
shown in the following figure. 



17 



M) MOTOROLA 



4-- 

3-- 

6- ~ 

7- ~ 
8 ~ 



C INPUTS J 



I*l*ct an INPUT <1 = > 0> or <q> to Qui*. 



t DIALOG 1 



The first clause of the first rule states: IF Angle IS Negative _Large. Press the 1 
key and the program displays the name Angle in the new rule window. The 
program displays a list of the membership functions for Angle in the Members 
window, as shown in the following figure. 



Know Lactam Bnu Qsrwrator < KBQ> U2.10 



<Copvrtfl*it Motorola Inc. JL991,1992> 




IF 



C CREATE ft MEM RULE i 



18 



M) MOTOROLA 



Koou lsckMt Dua Otnarator < KBQ) UZ.IO 
(Copyrl»ht Motorola Inc. X991.199Z) 



1 ~ rtr>q 1 • . , 

3 ~ 
4-~ 

3-" 
6-" 
l-~ 
8-*" 

t INPUT! 1 



3tW»*t ivaJMlun 

3- Hn»at lv«_*««l 1 

4- Zaro 

3 Po» It iv«_Srv«l 1 
t-Posltlv«JlBdluH 

7- Po* i t iv«_tar»a 

8- ~ 



[ HEMBEB3 1 



talact • MEMDER (1 = > 0). 



t DIftLPQ 1 



Now use the 1 key to select the membership function, Negative_Large. The 
program displays the member name in the new rule window and the dialog 
window asks for AND or THEN, as shown in the following figure. 



IF Arm la IX 



C CWEATE A NEW RULE I 



19 



M) MOTOROLA 



Know l«d9« Bmmm O«n*r«tor <KBQ) U3.10 
<Co«>url9ht HotoroU Inc. 1991,199l> 



4-" 

3-" 
*-" 
7-" 
8 " 



C INPUT* 3 



3-N*0«t lv«_J«»l 1 
3-Po»l t ivOna 1 1 
7-Poslt Ivajuiro* 



C MEMBER* I 



IF Anolo II Na«at iua_jL*r« 



t CTEATE A HEM BOLE 1 



I»l«ct <A> for AND or <T> for TtCM. 



t DIALOO I 



Rules that have one or more input clauses include the word AND to join the 
clauses. The rule that you are creating has two input clauses. Use the a key to add 
another input clause. The program retains the input windows on the screen, adds 
AND to the new rule window, and requests an input number in the dialog 
window. Note that each clause in the new rule window is written on a new line, 
with indention, to improve readability. The updated screen is shown in the 
following figure. 



20 



M) MOTOROLA 



Knoularfq* Bast Owwntor VRBC7 UZ.IO 



CCopvrlotit Motorola Inc. 1991.1992> 




IF An«l* IS No«<tiu«J.ania 
AND 



A-~ 

s-~ 

7-~ 
9 ~ 

C INPUTS 1 



1 -Hngat J v«_J_»rv« 

3- N*«at 1 v«_Sn» 1 1 

4- Z«ro 

3 - Pos 1 t i v«_S «• 1 1 
6 - Po* 1 1 1 v«_n«d i um 
7 - Pos 1 1 IvaJJkrga 



t«l*ct mn INPUT < 1 = > B > or <a> to qui*. 



The second clause of the first rule states: Delta_Angle IS Zero. Press the 2 key to 
select Delta_Angle and press the 4 key to select Zero. The second and last input 
clause is complete. The dialog window offers the choice of another input clause or 
entry of the first output clause, as shown in the following figure. 



I IPBtM 1 



I CREATE ft NEW RULE 1 



I DIALOG I 



21 



M) MOTOROLA 



Knoulwhw B«sa Gorvarator (KBO) U2.10 
CCoovir l<a»it Motorola Inc. 1991,1992) 



i-Arvala 

1 t«_/Wva 1- 

3- " 

5- ~ 

6- ~ 

7- ~ 

t INPUTS 1 



1-Haa a t lva_Larf« 

3- M*»st i«M_tna 1 1 

4- Zaro 

3 - Pd« 1 1 lva _SnaI 1 
7 - Pos 1 t Iv«_Lar«c 



C MEMBERS I 



IF Ortola IX N»o>at lv«JL>r« 
AND EX*1 ta_JV>gIa IS Zaro 



t CREATE A HEM RULE J 



t*l*ct <A> for AND or <T> Tor THEN. 



IDIAUOO 1 



Press the t key to enter an output clause. The program adds the word THEN in 
the new rules window, shows the output names in the right hand window, and 
requests an output selection in the dialog window, as shown in the following 
figure. 



22 




M) MOTOROLA 



Knowlada* &**m Oerv»r»tor <KSO> Ua.lO 



<Capurl«ht Motorola Inc. 1991,1993) 



a - 

3 _ 

4-~ 



l-HotorJCurr»nt 



IF Anal* IS Ne«jitivcJLarM 
AND D*lta_An«la IS Z«ro 

THEM 



[ OUTPUTS 1 



t CREATE ft HEM RULE I 



t*l*ct an OUTPUT <1 = > > or CR to quit. 



t DIALOG 1 



The first, and only, output clause of the desired rule states: Motor _Current IS 
Positive JLarge. Press the 1 key to select Motor_Current and the function 
membership window appears, listing the membership functions for output #1. 
Press the 7 key to select PositiveJLarge, as shown in the following figure. 



23 



(M) MOTOROLA 



KnoulMlw Base Oaoarator <KBO) V2.10 
(Copyright Motorola Inc. 1991,1993) 



l-Hotor_Curr«nt 
»-~ 

3- ~ 

4- ~ 



C OUTPUTS 1 



1 -M«o»t ioa_l_arg»a 
Z - Ha«a 1 1 imJWd I un 
S-Negat 1 v*_Sm 1 1 
4-Zaro 

3 Po» 1 1 lv«_XrtaI 1 
6 - Poa 1 1 1 va_J«aa I un 

7- Po» 1 1 ivaJLaraa 

8- - 



i members j 



IF Arm la IS M**at lua_JLar«a 

AND Da 1 t»_JVvu 1* IS Zaro 
THEM Hotor_Curr«nt IX Poa 1 1 lva_Lar-« 



C CREATE ft MEM RULE 1 



Seloot CA> tor AMD or <E> for END. 



C DIALOO I 



Since the rule you are creating has only one output clause, the rule is finished. 
Press the e key to terminate the rule. If the rule required more than one output 
clause, you could enter as many output clauses as desired by using the a key. The 
Dialog window goes away, and the completed rule is displayed as shown in the 
following figure. 



24 



(M) MOTOROLA 



Knoul«l9« Bma G»n«r«tor <KBO> U3.1D 
(Copurlaht Motorola Inc. 1991. 19M> 



A - Add New Rul*. 
D - Dalata a Rul*. 

Q - Quit. 

[ COMMAND I 



1-IF Aoala IS H*«atlu*_JL»r«a 
AND Dslta_AnsIa IS Zaro 

THEN Notor.Currant IS Pos 1 1 i\>«_l_s 



C CURRENT RtW-ES 1 



This completes entry of one rule. Enter all the remaining rules in a similar 
manner. When rule entry is complete, use the q key to return to the Main Menu. 
First, save the knowledge base data in a disk file. Use the s key to select the save 
command. The save command opens a window that contains the names of 
currently existing knowledge base files. You could select one of these and write 
your new knowledge base to one of these. However, type the word new in the 
window. This creates a new file named new.knb and writes the new knowledge 
base data into it. An example screen showing rules 13 through 15 is shown in the 
following figure. 

Knouladga B»« Generator <K8Q> U2.10 
(Copurloht Motorola Inc. 1991,1992) 



A - Add Hau Rula 
D - Dalata a Rula. 

Q - Quit. 

C COMMAND ] 



13- IF Ana la IS Pos It lwa_Xadlun 

AND Da 1 1 a_Aoa 1 a IS Zaro 
THEN Hotor_Currant IS Na«at tva_Madlun 

14- IF Ana la is PoftltlwaJLaro* 

AND Dalta_flrtala IS Zmro 
TIEN Hotor_Currant IS Naaat IvaJ-aroa 

13-IF Art« la IS Zaro 

AND Dalta_An«la IS Naoat iva_!nal 1 
THEN Motor_Cvir raot IS Pos » 1 lu*_tna 1 1 



t CURRENT W-ES 1 



This file now contains all the knowledge base data that you have just entered. It is 
the source code for the knowledge base. However, this is not the data required by 



25 



M) MOTOROLA 



the inference engine. The data must be scaled and encoded into constant bytes for 
the inference engine. Motorola assemblers require constant byte data to be coded 
as FCB directives. This is the last and most important function that KBG must 
perform. Use the a key to create an assembly language file, named new.asm. 

This concludes the tutorial showing the use of KBG to create the Knowledge base. 
File new.asm must now be merged with the source code for the inference engine 
fuzzy05b.asm or fuzzy lib. asm to create a fuzzy logic processor. Other user code 
used to perform I/O, non-fuzzy data processing, and conversion of data to/from 
fuzzy logic may also be added to the file. The following DOS commands could be 
used to perform the task, assuming that an MC68HC11 is the target MCU: 

C:> copy new.asm fuzz_app.asm 

C:> type fuzzy llb.asm »fuzz_app.asm 

C:> type othercode.asm »fuzz_app.asm 

Now the knowledge base, inference engine, and other user code is in a single file. 
The following DOS command assembles the application. This command line 
assumes the use of the Freeware assembler, AS11.EXE, which generates a 
listing, fuzz_app.lst, and an S-record file, fuzz_app.sl9. 

C:> asll -1 fuzz_app.asm >fuzz_app.lst 

You can program the file, fuzz_app.s 19, into PROM or download it into a 
development system to be debugged. 



26